package com.jdojo.control;

import com.jdojo.mvc.model.Person;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SimplestTableView1 extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
// Create a TableView with a list of persons
//         TableView<Person> table = new TableView<>(PersonTableUtil.getPersonList());
        TableView<Person> table = new TableView<>();
        table.setPlaceholder(new Label("无数据"));
// Add columns to the TableView
        TableColumn<Person, String> idCol = new TableColumn<>("Id");
        idCol.setCellValueFactory(new PropertyValueFactory<>("personId"));
        TableColumn<Person, String> fNameCol = new TableColumn<>("First");
        fNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));
        TableColumn<Person, String> lNameCol = new TableColumn<>("Last");
        lNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));
// Create Name column and nest First and Last columns in it
        TableColumn<Person, String> nameCol = new TableColumn<>("Name");
        nameCol.getColumns().addAll(fNameCol, lNameCol);

        table.getColumns().addAll(idCol, nameCol);
        VBox root = new VBox(table);
        root.setStyle("-fx-padding: 10;" +
                "-fx-border-style: solid inside;" +
                "-fx-border-width: 2;" +
                "-fx-border-insets: 5;" +
                "-fx-border-radius: 5;" +
                "-fx-border-color: blue;");
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Simplest TableView");
        stage.show();
    }
}